﻿#include "register.h"
#include "ui_register.h"
#include"SocketHelper.h"
#include<QMessageBox>
#include<message.h>
#include<QDebug>
Register::Register(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Register)
{
    ui->setupUi(this);
    setAttribute(Qt::WA_DeleteOnClose, true);
    ui->pwd_1->setEchoMode(QLineEdit::Password);//不显示密码
    ui->pwd_2->setEchoMode(QLineEdit::Password);//不显示密码
}

Register::~Register()
{
    qDebug()<<u8"Register析构";
    delete ui;
}


void Register::on_submit_clicked()
{
    qDebug()<<u8"注册中";
    if(ui->pwd_1->text().size() == 0){
        QMessageBox::information(this,u8"提示",u8"请输入密码");
        return;
    }else if(ui->pwd_1->text() != ui->pwd_2->text()){
        QMessageBox::information(this,u8"提示",u8"两次输入密码不一致");
        return;
    }else{
        //连接服务器
        SOCKET sockCli = SocktetUtil::openClientSocket("47.113.150.167", 6543);//192.168.147.128
        //发送登录请求
        Message m;
        m.messageType = 3;
        strcpy(m.messageContent,ui->pwd_1->text().toStdString().c_str());
        send(sockCli, (char*)&m,sizeof(m),0);//发送
        recv(sockCli,(char*)&m,1000,0);//等待接收服务端验证
        QString con = m.messageContent;
        con = "qq:" + con;
        QMessageBox::information(this,u8"成功",con);
        this->close();
    }
}
